package 美国疫情;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class RedTest extends Reducer<JavaBean, NullWritable, MysqlBean, NullWritable> {
    MysqlBean k = new MysqlBean();
    int sum_cases;
    int sum_deaths;

    @Override
    protected void reduce(JavaBean key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {
        for (NullWritable v : values) {
            sum_cases += key.getCases();
            sum_deaths += key.getDeaths();
        }
        String date = key.getDate().substring(0, key.getDate().length() - 3);
        k.set(date, key.getStats(), key.getFips(), sum_cases, sum_deaths);
        context.write(k,NullWritable.get());
        sum_deaths = 0;
        sum_cases = 0;
    }
}
